using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace CrmDocman.Common
{
	public class DBServer
	{

        private SqlConnection m_serverConnection;

        public SqlConnection ServerConnection {
            get {
                return m_serverConnection;
            }
            set {
                m_serverConnection = value;
            }
        }
		public DBServer()
		{
			m_serverConnection= new SqlConnection() ;
		}
		public bool ConnectToServer(string serName)
		{
			string s;
            s = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=" +
                serName + ";Packet Size=4096";
			m_serverConnection.ConnectionString = s;
			try 
			{
				m_serverConnection.Open() ;
				return true;
			}
			catch ( SqlException ex ) 
			{
				return false;
			}
		}
		public bool ConnectToServer( string mserName,string mUserName, string mPass)
		{
            string s;
            s = "Initial Catalog=master;Data Source={0};uid = {1}; password = {2}";
            s = string.Format(s, mserName, mUserName, mPass);
            m_serverConnection.ConnectionString = s;
            try
            {
                m_serverConnection.Open();
                return true;
            }
            catch (SqlException ex)
            {
                return false;
            }
		}

		public ArrayList  GetDBNames() 
		{
			ArrayList  s= new ArrayList();
			SqlCommand com = new SqlCommand();
			com.CommandType = CommandType.Text;
			com.Connection = m_serverConnection;
			com.CommandText = "Select Name from master..sysdatabases";
			SqlDataReader reader= com.ExecuteReader();
			while (reader.Read()) 
				s.Add(reader.GetValue(0));
			return s;
			
		}
	}
}
